#include "getpixmap.h"
#include <QDebug>

GetPixmap::GetPixmap(QObject *parent) :
    QObject(parent)
{

}

GetPixmap::~GetPixmap()
{

}

void GetPixmap::mjpeg_streamer_reply(QNetworkReply *reply)
{
    QByteArray byteArr = reply->readAll();

    QPixmap pix;
    pix.loadFromData(byteArr);

    emit get_getOnePixmap(pix);

    manager->get(*request);
    reply->deleteLater();
}



void GetPixmap::run()
{
    QString url;

    url.append("http://" + get_ipAddr + ":" + get_port + "/?action=snapshot");
    qDebug() << url;

    //    qDebug() << "ipAddr:" << get_ipAddr;
    //    qDebug() << "port:" << get_port;

    manager = new QNetworkAccessManager();
    request = new QNetworkRequest(QUrl(url));
    connect(manager,SIGNAL(finished(QNetworkReply*)), this, SLOT(mjpeg_streamer_reply(QNetworkReply*)));
    manager->get(*request);
}
